// PEDebug.h: interface for the PEDebug class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_PEDEBUG_H__D7AE83A6_4E94_4E9B_8F06_41ADB4D7A9EB__INCLUDED_)
#define AFX_PEDEBUG_H__D7AE83A6_4E94_4E9B_8F06_41ADB4D7A9EB__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


class DumpBuffer;

class PE_Debug
{
public :
    PE_Debug() ;
    ~PE_Debug() ;
    void ClearReport() ;
    void DumpDebugInfo( DumpBuffer& dumpBuffer, const BYTE* caller, HINSTANCE hInstance ) ;
    void Display() ;
private :
    // Report data
    enum { MAX_MODULENAME_LEN = 512, MAX_FILENAME_LEN = 256 } ;
    char latestModule[ MAX_MODULENAME_LEN ] ;
    char latestFile[ MAX_FILENAME_LEN ] ;
    // File mapping data
    HANDLE hFile ;
    HANDLE hFileMapping ;
    PIMAGE_DOS_HEADER fileBase ;
    // Pointers to debug information
    PIMAGE_NT_HEADERS NT_Header ;
    PIMAGE_COFF_SYMBOLS_HEADER COFFDebugInfo ;
    PIMAGE_SYMBOL COFFSymbolTable ;
    int COFFSymbolCount ;
    const char* stringTable ;
	
    void ClearFileCache() ;
    void ClearDebugPtrs() ;
    void MapFileInMemory( const char* module ) ;
    void FindDebugInfo() ;
    void DumpSymbolInfo( DumpBuffer& dumpBuffer, DWORD relativeAddress ) ;
    void DumpLineNumber( DumpBuffer& dumpBuffer, DWORD relativeAddress ) ;
    PIMAGE_COFF_SYMBOLS_HEADER GetDebugHeader() ;
    PIMAGE_SECTION_HEADER SectionHeaderFromName( const char* name ) ;
    const char* GetSymbolName( PIMAGE_SYMBOL sym ) ;
};

#endif // !defined(AFX_PEDEBUG_H__D7AE83A6_4E94_4E9B_8F06_41ADB4D7A9EB__INCLUDED_)
